package com.li.youhappygo.util;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.apache.commons.lang3.time.DateUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class JWTUtil {
    private static final String SECRET = "youhappygo";
    private Map<String, Object>parseJWT(String token)
    {
        Map<String,Object> claims = new HashMap<>();
        claims = Jwts.parser()
                .setSigningKey(SECRET)
                .parseClaimsJws(token)
                .getBody();
        return claims;
    }
    private String createJWT(Map<String,Object> claims){
        Map<String,Object>header = new HashMap<>();
        header.put("typ","JWT");
        header.put("alg","HS256");
        String token = Jwts.builder()
                .setClaims(claims)
                .setHeader(header)
                .setExpiration(new Date(System.currentTimeMillis() + 3 * 3600 * 1000))
                .setIssuedAt(new Date())
                .signWith(SignatureAlgorithm.HS256, SECRET)
                .compact();
        return token;
    }
}
